﻿'Description:废品单信息打印
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:YangJiang
'create Date:2018-3-29
'Rewriter:
'Rewrite Date:

Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports Camstar.WebClient.FormsBuilder.WebForm
Imports Camstar.WebClient.WebServicesProxy.InSiteWebServices
Imports System.IO
Imports Camstar.WebClient.WebConstants
Imports BusinessRule.IBusiness
Imports BusinessRule.DTO
Imports BusinessRule.BusinessFactory
Imports BusinessRule.Common
Partial Class forms_ButtonTestyj_ScrapProductInfoPrint
    Inherits System.Web.UI.Page

    Private m_UserInfo As New CurrentUserInfo
    Private m_ScrapInfoBusiness As uLMSScrapInfoIBusiness = uMESBusinessFactory.instance.GetuLMSScrapInfoBusinessObject

    Dim ZFPDBH As String '废品单号
    Dim ZZFPLX As String '废品类型
    Dim FERTAUFNR As String '生产订单
    Dim ZJX As String '型别
    Dim ProductName As String '零件号
    Dim ZPCH As String '机加批次
    Dim ProductDescription As String '零件名称
    Dim ZYWLH As String '原料物料号
    Dim ZLPH As String '炉批号   原料炉批号的取值，炉批号为空，取原料收货批次号
    'Dim ZYWLPC1 As String '原料收货批次号
    Dim FERTVORNR As String '工序号
    Dim ZGD As String '工段
    Dim ZFPSL As String '报废数量
    Dim ZFPZL As String '报废重量
    Dim FECOD As String '缺陷-代码，原因代码
    Dim ZZFPPLY As String '生产单位
    Dim ZZRDW As String '责任单位
    Dim ZBZ As String '备注
    Dim ZJYY As String '检验员
    Dim ZJYSZR As String '检验室主任
    Dim ZZRZ As String '责任者
    Dim CreateDate As String '报废时间
    Dim ZQXTXT As String '主题长文本，不合格品特征 


    Dim ContainerID As String = ""
    Dim FactoryID As String = ""
    Dim IDs As StringBuilder
    Dim strID() As String
    Dim count As Integer = 0

    Public strHtmlTable As String
    Public strHtmlTables(0 To 100) As String
    Dim sbHtml As New StringBuilder

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            If IDs Is Nothing Then
                If IsNothing(Session("IDs")) = False Then
                    IDs = Session("IDs")
                    Session.Remove("IDs")
                Else
                    'Response.Write("<script type='text/javascript'>alert('请选择要打印的废品单');window.close();</script>")
                    Return
                End If

            End If

            iniPage(IDs)
        End If
    End Sub

    Private Sub iniPage(ByVal IDs As StringBuilder)
        m_UserInfo = Session("CurrentUserInfo")
        Dim para As New Dictionary(Of String, String)
        Dim strHtmlTitle As String
        Dim strHtmlTableMain As String
        Dim strHtmlTableDetails As String
        Dim strSplitInfo As String
        Dim strBomDetails As String
        para.Add("FactoryID", m_UserInfo.FactoryID)
        para.Add("CurrentPageIndex", 1)
        para.Add("PageSize", 1)

        Dim ContainerStepScrapInfoID() As String
        Dim str As String = IDs.ToString
        Dim str1 As String = ""
        If IsNothing(Session("ContainerStepScrapInfoIDs")) = False Then
            str1 = Session("ContainerStepScrapInfoIDs").ToString
            str1 = str1.Substring(0, str1.Length - 1)
            ContainerStepScrapInfoID = str1.Split(",")
            Session.Remove("ContainerStepScrapInfoIDs")
        Else
            ContainerStepScrapInfoID = Nothing
        End If
        str = str.Substring(0, str.Length - 1)
        strID = str.Split(",")
        Dim result As New uMESProcessResult
        ReDim strHtmlTables(0 To strID.Length - 1)
        For i = 0 To strID.Length - 1
            para.Add("ContainerID", strID(i))
            strHtmlTableDetails = SetTableDetail()
            strHtmlTitle = SetTableTitle()
            strSplitInfo = SetSplitInfo()
            strBomDetails = SetBomDetail()
            If ContainerStepScrapInfoID Is Nothing Then
                result = m_ScrapInfoBusiness.GetScrapInfoUnchecked(para)
            Else
                para.Add("ContainerStepScrapInfoID", ContainerStepScrapInfoID(i))
                result = m_ScrapInfoBusiness.GetScrapInfoCheck(para)
            End If
            Dim dt As New DataTable
            If result.Result Then
                dt = result.DBTable
            Else
                Exit Sub
            End If
            count = i

            strHtmlTableMain = SetTableMain(dt)

            strHtmlTables(i) = String.Format("{0}{1}{2}{3}{4}{5}", strHtmlTables(i), strHtmlTitle, strHtmlTableMain, strHtmlTableDetails, strSplitInfo, strBomDetails)

            para.Remove("ContainerID")
            If para.Keys.Contains("ContainerStepScrapInfoID") Then
                para.Remove("ContainerStepScrapInfoID")
            End If
        Next

    End Sub

    Private Function SetTableMain(ByVal dt As DataTable) As String
        SetTableMain = String.Empty
        sbHtml.Clear()

        If dt.Rows.Count > 0 Then '给字段赋值
            If dt.Columns.Contains("ZFPDBH") Then
                ZFPDBH = dt.Rows(0)("ZFPDBH").ToString()
            End If
            If dt.Columns.Contains("ZZFPLX") Then
                Select Case dt.Rows(0)("ZZFPLX").ToString
                    Case "01"
                        ZZFPLX = "加工原因报废"
                    Case "02"
                        ZZFPLX = "材质原因报废"
                    Case "03"
                        ZZFPLX = "试验报废"
                    Case "04"
                        ZZFPLX = "节余报废"
                    Case "05"
                        ZZFPLX = "委外加工报废"
                    Case "10"
                        ZZFPLX = "其他报废"
                End Select
            End If

            FERTAUFNR = dt.Rows(0)("FERTAUFNR").ToString
            If dt.Columns.Contains("ZJX") Then
                ZJX = dt.Rows(0)("ZJX").ToString
            End If

            ProductName = dt.Rows(0)("ProductName").ToString
            ZPCH = dt.Rows(0)("ZPCH").ToString
            ZPCH = ZPCH.Substring(ZPCH.IndexOf("/") + 1)
            ProductDescription = dt.Rows(0)("ProductDescription").ToString
            If dt.Columns.Contains("ZYWLH") Then
                ZYWLH = dt.Rows(0)("ZYWLH").ToString
            End If

            FERTVORNR = dt.Rows(0)("FERTVORNR").ToString
            If dt.Columns.Contains("ZGD") Then
                ZGD = dt.Rows(0)("ZGD").ToString
            End If
            If dt.Columns.Contains("ZFPSL") Then
                ZFPSL = dt.Rows(0)("ZFPSL").ToString
            Else
                ZFPSL = dt.Rows(0)("LossQty").ToString
            End If
            If dt.Columns.Contains("ZFPZL") Then
                ZFPZL = dt.Rows(0)("ZFPZL").ToString
            End If
            If dt.Columns.Contains("FECOD") Then
                FECOD = dt.Rows(0)("FECOD").ToString
            End If
            If dt.Columns.Contains("ZZFPPLY") Then
                'Select Case dt.Rows(0)("ZZFPPLY").ToString
                '    Case "600"
                '        ZZFPPLY = "盘轴制造分厂"
                '    Case "601"
                '        ZZFPPLY = "机匣制造分厂"
                '    Case "602"
                '        ZZFPPLY = "热表处理分厂"
                '    Case "603"
                '        ZZFPPLY = "装配试车分厂"
                '    Case "607"
                '        ZZFPPLY = "燃烧部件制造分厂"
                '    Case "608"
                '        ZZFPPLY = "锻造叶片分厂"
                '    Case "609"
                '        ZZFPPLY = "结构件分厂"
                'End Select
                Dim s = dt.Rows(0)("ZZFPPLY").ToString
                If s.Contains("-") Then
                    ZZFPPLY = s.Substring(s.IndexOf("-") + 1)
                Else
                    ZZFPPLY = s
                End If
            End If
            If dt.Columns.Contains("ZZRDW") Then
                ZZRDW = dt.Rows(0)("ZZRDW").ToString
            End If
            If dt.Columns.Contains("ZBZ") Then
                ZBZ = dt.Rows(0)("ZBZ").ToString
            End If

            ZJYY = dt.Rows(0)("ZJYY").ToString
            If dt.Columns.Contains("ZJYSZR") Then
                ZJYSZR = dt.Rows(0)("ZJYSZR").ToString
            End If
            If dt.Columns.Contains("ZZRZ") Then
                ZZRZ = dt.Rows(0)("ZZRZ").ToString
            End If

            CreateDate = dt.Rows(0)("CreateDate").ToString
            CreateDate = CreateDate.Substring(0, CreateDate.IndexOf(" "))
            CreateDate = CreateDate.Replace("/", ".")
            If dt.Columns.Contains("ZQXTXT") Then
                ZQXTXT = dt.Rows(0)("ZQXTXT").ToString
            End If

            If dt.Rows(0)("ZLPH").ToString = "" And dt.Columns.Contains("ZYWLPC1") Then
                ZLPH = dt.Rows(0)("ZYWLPC1").ToString
            Else
                ZLPH = dt.Rows(0)("ZLPH").ToString
            End If
        End If


        sbHtml.AppendLine("<table width='360'  style='font-size:12px'>")
        sbHtml.AppendLine("<tr><td colspan='4'><center><font style='font-weight:bold;font-size:15px'>中国航发贵州黎阳航空动力有限公司废品通知单</font></center></td></tr>")
        sbHtml.AppendLine("<tr align='left'><td width='18%'>废品单号：</td><td width='34%'>" + ZFPDBH + "</td><td width='20%'>废品类型：</td><td width='28%'>" + ZZFPLX + "</td></tr></table>")

        sbHtml.AppendLine("<table width='360'  style='font-size:12px' class='tab'><tr><td>生产订单</td><td colspan='2'>" + FERTAUFNR + "</td><td width='20%'>型别</td><td colspan='2'>" + ZJX + "</td></tr>")
        sbHtml.AppendLine("<tr><td>零件号</td><td colspan='2'>" + ProductName + "</td><td>机加批次号</td><td colspan='2'>" + ZPCH + "</td></tr><tr><td>零件名称</td><td colspan='5'>" + ProductDescription + "</td></tr>")
        sbHtml.AppendLine("<tr><td>原料物料号</td><td colspan='2'>" + ZYWLH + "</td><td>原料炉批号</td><td colspan='2'>" + ZLPH + "</td></tr>")
        sbHtml.AppendLine("<tr><td>原料描述</td><td colspan='5'></td></tr><tr><td>工序号</td><td colspan='2'>" + FERTVORNR + "</td><td>工段</td><td colspan='2'>" + ZGD + "</td></tr>")
        sbHtml.AppendLine("<tr><td>报废数量</td><td colspan='2'>" + ZFPSL + "</td><td>报废重量</td><td colspan='2'>" + ZFPZL + "</td></tr>")
        sbHtml.AppendLine("<tr><td colspan='6'><div align='left'><p>不合格品特征：</p><p>" + ZQXTXT + "</p></div></td></tr>")
        sbHtml.AppendLine("<tr><td>原因代码</td><td colspan='5'>" + FECOD + "</td></tr><tr><td>生产单位</td><td colspan='5'>" + ZZFPPLY + "</td></tr>")
        sbHtml.AppendLine("<tr><td>责任单位</td><td colspan='5'>" + ZZRDW + "</td></tr><tr><td>备注</td><td colspan='5'>" + ZBZ + "</td></tr>")
        sbHtml.AppendLine("<tr><td width='18%'>检验员</td><td width='16%'>" + ZJYY + "</td><td width='18%'>检验室主任</td><td width='16%'>" + ZJYSZR + "</td><td width='15%'>责任者</td><td width='17%'>" + ZZRZ + "</td></tr></table>")

        sbHtml.AppendLine("<table width='360'  style='font-size:12px'><tr><td width='72%' style='text-align:right'>报废日期：</td><td width='28%' style='text-align:left'>" + CreateDate + "</td>")
        sbHtml.AppendLine("</tr></table><p>&nbsp;</p>")


        strHtmlTables(count) = sbHtml.ToString
    End Function


    Private Function SetTableDetail() As String
        SetTableDetail = String.Empty
    End Function

    Private Function SetTableTitle() As String
        SetTableTitle = String.Empty
    End Function

    Private Function SetSplitInfo() As String
        SetSplitInfo = String.Empty
    End Function

    Private Function SetBomDetail() As String
        SetBomDetail = String.Empty
    End Function

End Class
